﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Model;
using AspNetCs.Bll;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Enumerations.memorial_enum;

public partial class Users_EditMemorial : BasePage
{
    protected int id = 0;
    protected memorial_model MemorialModel = new memorial_model();
    protected Memorial MemorialBll = new Memorial();
    protected Memorial_Type_Model MemorialTypeModel = new Memorial_Type_Model();

    protected int CurrTypeInt = 1;
    protected int EnumTypeInt = (int)Person_TypeInt_Enum.both;
    protected int IsPwdUI = 0;
    protected string PwdShow = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx", "请您登录", true);
        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }
        if (id <= 0)
        {
            ShowMsgBack("参数传递错误！");
            Response.End();
        }

        Base_CurrPath = Base_CurrPath + " >> 会员管理中心 >> 纪念馆管理 >> 修改信息";
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/EditMemorial_" + id + ".Aspx", "", true);

        MemorialModel = MemorialBll.GetModel(id);
        if (Base_GetLoginInfo.GetUserID != MemorialModel.CreateId)
        {
            ShowMsgBack("当前纪念馆不属于您创建,你暂时不能对她进行管理");
            Response.End();
        }


        if (!Page.IsPostBack)
        {
            EditBind();

        }
        CurrTypeInt = MemorialTypeModel.TypeInt;
        IsPwdUI = MemorialModel.IsEncrypt;
        if (IsPwdUI == 1)
        {
            PwdShow = EncryptString.GetDecrypt(MemorialModel.GetPwd);
        }


    }

    protected void EditBind()
    {

        MemorialTypeModel = new Memorial_Type().GetModel(StringHelper.isNumber_int(MemorialModel.Memorial_Type.ToString()));


        this.Typeid.Value = MemorialModel.Memorial_Type.ToString();
        this.lb_Type.Text = MemorialTypeModel.TypeName;
        this.Txt_Number.Text = MemorialModel.NumId;
        this.Txt_Number.Enabled = false;
        this.Txt_Name.Text = MemorialModel.Names;
        this.Txt_UserNa.Text = MemorialModel.Surname;
        this.Txt_UserName.Text = MemorialModel.UserName;
        this.Txt_otherName.Text = MemorialModel.OtherName;
        EnumDescription[] Sex_Ed = EnumDescription.GetFieldTexts(typeof(Sex_Enum), EnumDescription.SortType.Rank);
        EnumDescription[] Ed = EnumDescription.GetFieldTexts(typeof(TimeType_enum), EnumDescription.SortType.Rank);
        this.Radio_Sex.DataTextField = "EnumDisplayText";
        this.Radio_Sex.DataValueField = "EnumDisplayText";
        this.Radio_Sex.DataSource = Sex_Ed;
        this.Radio_Sex.DataBind();
        this.Radio_Sex.Items.FindByValue(MemorialModel.Sex).Selected = true;
        this.Radio_Sex.RepeatColumns = 5;
        this.Txt_UpImg.Text = MemorialModel.Picture;
        this.Txt_Race.Text = MemorialModel.Nation;
        this.Txt_place.Text = MemorialModel.Place;
        this.Txt_Occu.Text = MemorialModel.Occupation;
        this.Txt_Belief.Text = MemorialModel.Belief;


        if (MemorialModel.BirthType == TimeType_enum.pub.ToString())
        {
            this.Txt_birthyear.Text = MemorialModel.Birthday;
        }
        else
        {
            this.Txt_birthyear.Text = MemorialModel.LunarCalendar_Birth;
        }
        this.DD_TimeType.DataTextField = "EnumDisplayText";
        this.DD_TimeType.DataValueField = "EnumValueStr";
        this.DD_TimeType.DataSource = Ed;
        this.DD_TimeType.DataBind();
        this.DD_TimeType.Items.FindByValue(MemorialModel.BirthType).Selected = true;



        if (MemorialModel.DepartType == TimeType_enum.pub.ToString())
        {
            this.Txt_DeathTime.Text = MemorialModel.DepartTime;
        }
        else
        {
            this.Txt_DeathTime.Text = MemorialModel.LunarCalendar_depart;
        }
        this.DD_DeathType.DataTextField = "EnumDisplayText";
        this.DD_DeathType.DataValueField = "EnumValueStr";
        this.DD_DeathType.DataSource = Ed;
        this.DD_DeathType.DataBind();
        this.DD_DeathType.Items.FindByValue(MemorialModel.DepartType).Selected = true;

        if (MemorialTypeModel.TypeInt == (int)Person_TypeInt_Enum.single
)
        {
            this.TwoPanel.Visible = false;
        }
        else
        {
            this.TwoPanel.Visible = true;
            this.Txt_SnameTwo.Text = MemorialModel.Surname_two;
            this.Txt_unameTwo.Text = MemorialModel.UserName_two;
            this.Txt_OtherNameTwo.Text = MemorialModel.OtherName_two;


            this.Txt_SexTwo.DataTextField = "EnumDisplayText";
            this.Txt_SexTwo.DataValueField = "EnumDisplayText";
            this.Txt_SexTwo.DataSource = Sex_Ed;
            this.Txt_SexTwo.DataBind();
            this.Txt_SexTwo.Items.FindByValue(MemorialModel.Sex_two).Selected = true;

            this.Txt_SexTwo.RepeatColumns = 5;
            this.Txt_UppicTwo.Text = MemorialModel.Picture_two;
            this.Txt_RaceTwo.Text = MemorialModel.Nation_two;
            this.Txt_placeTwo.Text = MemorialModel.Place_two;
            this.Txt_OccuTwo.Text = MemorialModel.Occupation_two;
            this.Txt_BeliefTwo.Text = MemorialModel.Belief_two;


            if (MemorialModel.BirthType_Two == TimeType_enum.pub.ToString())
            {
                this.Txt_birthTwo.Text = MemorialModel.Birthday_two;
            }
            else
            {
                this.Txt_birthTwo.Text = MemorialModel.LunarCalendar_Birth_two;
            }
            this.Txt_birChangeTwo.DataTextField = "EnumDisplayText";
            this.Txt_birChangeTwo.DataValueField = "EnumValueStr";
            this.Txt_birChangeTwo.DataSource = Ed;
            this.Txt_birChangeTwo.DataBind();
            this.Txt_birChangeTwo.Items.FindByValue(MemorialModel.BirthType_Two).Selected = true;


            if (MemorialModel.DepartType_Two == TimeType_enum.pub.ToString())
            {
                this.Txt_DeathTimeTwo.Text = MemorialModel.DepartTime_two;
            }
            else
            {
                this.Txt_DeathTimeTwo.Text = MemorialModel.LunarCalendar_depart_two;
            }
            this.DD_DeathTimeTwo.DataTextField = "EnumDisplayText";
            this.DD_DeathTimeTwo.DataValueField = "EnumValueStr";
            this.DD_DeathTimeTwo.DataSource = Ed;
            this.DD_DeathTimeTwo.DataBind();
            this.DD_DeathTimeTwo.Items.FindByValue(MemorialModel.DepartType_Two).Selected = true;

        }


        IsPwd.Items.FindByValue(MemorialModel.IsEncrypt.ToString()).Selected = true;
        this.WebEditor1.Text = MemorialModel.ReadMe;




    }



    protected void Button1_Click(object sender, EventArgs e)
    {

        memorial_model md = new memorial_model();

        md.Id = id;
        md.IsCheck = 1;
        md.NetIp = StringHelper.Ip();
        md.Names = StringHelper.HtmlEncrypt(Txt_Name.Text.ToString().Trim());

        if (md.Names == "")
        {
            ShowMsgBack("纪念馆名称不能为空");
            Response.End();
        }

        md.Surname = StringHelper.HtmlEncrypt(Txt_UserNa.Text.ToString().Trim());
        md.UserName = StringHelper.HtmlEncrypt(Txt_UserName.Text.ToString().Trim());
        md.OtherName = StringHelper.HtmlEncrypt(Txt_otherName.Text.ToString().Trim());
        md.Sex = Radio_Sex.SelectedValue;
        md.Picture = StringHelper.HtmlEncrypt(Txt_UpImg.Text.ToString().Trim());
        if (md.Picture == "")
        {
            md.Picture = "images/nopic.jpg";
        }

        md.Nation = StringHelper.HtmlEncrypt(Txt_Race.Text.ToString().Trim());
        md.Place = StringHelper.HtmlEncrypt(Txt_place.Text.ToString().Trim());
        md.Occupation = StringHelper.HtmlEncrypt(Txt_Occu.Text.ToString().Trim());
        md.Belief = StringHelper.HtmlEncrypt(Txt_Belief.Text.ToString().Trim());
        md.BirthType = DD_TimeType.SelectedValue;

        if (md.BirthType == TimeType_enum.pub.ToString())
        {
            md.Birthday = StringHelper.HtmlEncrypt(Txt_birthyear.Text.ToString().Trim());
            if (StringHelper.isDatetime_Bool(md.Birthday))
            {
                md.LunarCalendar_Birth = StringHelper.ChineseLunisolarDate(StringHelper.isDatetime(md.Birthday));
            }

        }
        else
        {
            md.LunarCalendar_Birth = StringHelper.HtmlEncrypt(Txt_birthyear.Text.ToString().Trim());
        }



        md.DepartType = DD_DeathType.SelectedValue;

        if (md.DepartType == TimeType_enum.pub.ToString())
        {
            md.DepartTime = StringHelper.HtmlEncrypt(Txt_DeathTime.Text.ToString().Trim());

            if (StringHelper.isDatetime_Bool(md.DepartTime))
            {
                md.LunarCalendar_depart = StringHelper.ChineseLunisolarDate(StringHelper.isDatetime(md.DepartTime));
            }
        }
        else
        {
            md.LunarCalendar_depart = StringHelper.HtmlEncrypt(Txt_DeathTime.Text.ToString().Trim());
        }




        md.Surname_two = StringHelper.HtmlEncrypt(Txt_SnameTwo.Text.ToString().Trim());
        md.UserName_two = StringHelper.HtmlEncrypt(Txt_unameTwo.Text.ToString().Trim());
        md.OtherName_two = StringHelper.HtmlEncrypt(Txt_OtherNameTwo.Text.ToString().Trim());
        md.Sex_two = Txt_SexTwo.SelectedValue;
        md.Picture_two = StringHelper.HtmlEncrypt(Txt_UppicTwo.Text.ToString().Trim());
        if (md.Picture_two == "")
        {
            md.Picture_two = "images/nopic.jpg";
        }
        md.Nation_two = StringHelper.HtmlEncrypt(Txt_RaceTwo.Text.ToString().Trim());
        md.Place_two = StringHelper.HtmlEncrypt(Txt_placeTwo.Text.ToString().Trim());
        md.Occupation_two = StringHelper.HtmlEncrypt(Txt_OccuTwo.Text.ToString().Trim());
        md.Belief_two = StringHelper.HtmlEncrypt(Txt_BeliefTwo.Text.ToString().Trim());



        md.BirthType_Two = Txt_birChangeTwo.SelectedValue;

        if (md.BirthType_Two == TimeType_enum.pub.ToString())
        {
            md.Birthday_two = StringHelper.HtmlEncrypt(Txt_birthTwo.Text.ToString().Trim());

            if (StringHelper.isDatetime_Bool(md.Birthday_two))
            {
                md.LunarCalendar_Birth_two = StringHelper.ChineseLunisolarDate(StringHelper.isDatetime(md.Birthday_two));
            }


        }
        else
        {
            md.LunarCalendar_Birth_two = StringHelper.HtmlEncrypt(Txt_birthTwo.Text.ToString().Trim());
        }

        md.DepartType_Two = DD_DeathTimeTwo.SelectedValue;

        if (md.DepartType_Two == TimeType_enum.pub.ToString())
        {
            md.DepartTime_two = StringHelper.HtmlEncrypt(Txt_DeathTime.Text.ToString().Trim());

            if (StringHelper.isDatetime_Bool(md.DepartTime_two))
            {
                md.LunarCalendar_depart_two = StringHelper.ChineseLunisolarDate(StringHelper.isDatetime(md.DepartTime_two));
            }

        }
        else
        {
            md.LunarCalendar_depart_two = StringHelper.HtmlEncrypt(Txt_DeathTime.Text.ToString().Trim());
        }

        md.IsEncrypt = StringHelper.isNumber_int(IsPwd.SelectedValue);
        if (md.IsEncrypt == 1)
        {
            md.GetPwd = EncryptString.GetEncrypt(Txt_Pwdchange.Text);
        }
        if (Request["provice"] != null)
        {
            md.Province = StringHelper.isNumber_int(Request["provice"].ToString());

        }
        if (md.Province > 0)
        {
            if (Request["city"] != null)
            {
                md.City = StringHelper.isNumber_int(Request["city"].ToString());
            }
        }
        md.ReadMe = WebEditor1.Text;
        string InfoMsg = "";
        if (MemorialBll.Update(md, out InfoMsg) > 0)
        {
            ResultStr("EditMemorial_" + id + ".Aspx", InfoMsg, true);
        }
        else
        {
            ShowMsgBack(InfoMsg);
        }










    }
}
